﻿using Basic.HrGatewayModular.Interface;
using Basic.HrGatewayModular.Model.EmpLogin;
using Basic.HrRemoteModel.Emp.Model;
using WeDonekRpc.Helper.Validate;
using WeDonekRpc.HttpApiGateway;

namespace Basic.HrGatewayModular.Api
{
    internal class EmpLoginApi : ApiController
    {
        private readonly IEmpLoginService _Service;
        public EmpLoginApi ( IEmpLoginService service )
        {
            this._Service = service;
        }
        /// <summary>
        /// 检查权限
        /// </summary>
        /// <param name="power"></param>
        /// <returns></returns>
        public string[] CheckPower ( [NullValidate("hr.power.null")] string[] power )
        {
            if ( this.UserState.IsAdmin() )
            {
                return power;
            }
            return this.UserState.Power.Intersect(power).ToArray();
        }
        /// <summary>
        /// 获取登陆资料
        /// </summary>
        /// <returns></returns>
        public LoginDatum GetLoginDatum ()
        {
            return this._Service.GetLoginDatum(this.UserState);
        }
        /// <summary>
        /// 切换公司
        /// </summary>
        /// <param name="companyId"></param>
        /// <returns></returns>
        public LoginDatum Switch ( [NumValidate("hr.company.id.error", 1)] long companyId )
        {
            return this._Service.Switch(this.UserState, companyId);
        }

        /// <summary>
        /// 修改个人资料
        /// </summary>
        /// <param name="obj"></param>
        public void SetPerson ( PersonDatum obj )
        {
            this._Service.SetDatum(base.UserState.ToEmpId(), obj);
        }
        public void LoginOut ()
        {
            this.CancelAccredit();
        }
        public void CheckIsLogin ()
        {
        }
    }
}
